package ownLinkedlist;

public class OwnLinkedListDemo {
    public static void main(String[] args) {
        String[] strDemo = new String[]{"a", "b", "c", "d", "e"};
        LinkedList<String> own = new LinkedList<String>(strDemo);

        System.out.println("List: " + own.toString());

        System.out.println("Contains a: " + own.contains("a"));
        System.out.println("Contains e: " + own.contains("e"));
        System.out.println("Contains d: " + own.contains("d"));
        System.out.println("Contains f: " + own.contains("f"));
        System.out.println("Size: " + own.getListSize());
        System.out.println("HeadElement: " + own.getHeadNode());
        System.out.println("TailElement: " + own.getTailNode());

        own.addNewFirst("Hello, World!");
        own.add("BB, America!");
        System.out.println("NewSize: " + own.getListSize());
        System.out.println("NewHeadElement: " + own.getHeadNode());
        System.out.println("NewTailElement: " + own.getTailNode());
        System.out.println("0th element: " + own.getElement(0));
        System.out.println("1st element: " + own.getElement(1));
        System.out.println("501th element [actually no]: " + own.getElement(501));
        System.out.println("List: " + own.toString());

        own.removeNodeByIndex(1);
        own.removeNodeByIndex(1);
        System.out.println("List: " + own.toString());
        System.out.println("Size: " + own.getListSize());

        System.out.println("AscendingIterator: ");
        OwnIterator ai = (OwnIterator) own.iterator();
        StringBuilder out = new StringBuilder();
        while (ai.hasNext()) {
            ai.next();
            out.append("||").append(ai.getElement());
        }

        System.out.println(out.toString());

        System.out.println("DescendingIterator: ");
        OwnIterator di = (OwnIterator) own.iterator();
        if(di.isAscending())
            di.switchToDescending();
        di.moveToTail();
        StringBuilder out2 = new StringBuilder();
        while (di.hasNext()) {
            di.next();
            out2.append("||").append(di.getElement());
        }

        System.out.println(out2.toString());


        own.clear();
        System.out.println("Size: " + own.getListSize());
    }
}
